﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Extensil.Common;
using System.IO;
using System.Configuration;

namespace Vibz.TeamAssignment
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            try
            {
                using(StreamWriter writer = new StreamWriter("extensilConsole.log"))
                {
                    bool log = false;
                    string allowLogging = ConfigurationManager.AppSettings["AllowLogging"];
                    if(!String.IsNullOrEmpty(allowLogging) && bool.TryParse(allowLogging, out log) && log)
                        Console.SetOut(writer);
                    Application.Run(new ViewAssignment());
                }
            }
            catch(Exception exc)
            {
                AlertBox.ShowDialog("Due to some serious problem the application will get closed. We apologise for your inconvenience. \r\nDetails:\r\n\t" + LinkedException(exc));
            }
        }
        static string LinkedException(Exception exc)
        {
            return exc.Message + "-[" + exc.StackTrace + "]" + "\r\n\t" + (exc.InnerException == null ? "" : LinkedException(exc.InnerException));
        }
    }
}
